VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsFormSetup"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'xwelx 04.2010

Option Explicit

Public Sub FormLocking(bval As Boolean)

    For Each objCtl In FrmName
        If TypeName(objCtl) = "ITGTextBox" Then
            objCtl.Locked = bval
            objCtl.LabelForeColor = &H0&
        ElseIf TypeName(objCtl) = "TextBox" Then
            objCtl.Locked = bval
        ElseIf TypeName(objCtl) = "ITGCommandButton" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "CommandButton" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "ComboBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "MaskEdBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "ITGDateBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "ITGCheckBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "OptionButton" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "DataGrid" Then
            objCtl.AllowUpdate = Not bval
        ElseIf TypeName(objCtl) = "RichTextBox" Then
            objCtl.Locked = bval
'        ElseIf TypeName(objCtl) = "Frame" Then
'            objCtl.Enabled = Not bval
        End If
    Next
End Sub

Public Sub FormSearch(bval As Boolean)
    For Each objCtl In FrmName
        If TypeName(objCtl) = "ITGTextBox" Then
            If objCtl.Mandatory = True Then
                objCtl.Locked = Not bval
                objCtl.LabelForeColor = &HC00000
            Else
                objCtl.Locked = bval
            End If
        ElseIf TypeName(objCtl) = "TextBox" Then
            objCtl.Locked = bval
        ElseIf TypeName(objCtl) = "ITGCommandButton" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "CommandButton" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "ComboBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "MaskEdBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "ITGDateBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "ITGCheckBox" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "OptionButton" Then
            objCtl.Enabled = Not bval
        ElseIf TypeName(objCtl) = "DataGrid" Then
            objCtl.AllowUpdate = Not bval
        ElseIf TypeName(objCtl) = "RichTextBox" Then
            objCtl.Locked = bval
        End If
    Next
End Sub

Public Sub TextClearing()
    For Each objCtl In FrmName
        If TypeName(objCtl) = "ITGTextBox" Then
            objCtl.Text = ""
        ElseIf TypeName(objCtl) = "TextBox" Then
            objCtl.Text = ""
        ElseIf TypeName(objCtl) = "RichTextBox" Then
            objCtl.Text = ""
        ElseIf TypeName(objCtl) = "MaskEdBox" Then
            objCtl.Mask = "99/99/9999"
        ElseIf TypeName(objCtl) = "ITGDateBox" Then
            objCtl.Text = "__/__/____"
        ElseIf TypeName(objCtl) = "ITGCheckBox" Then
            objCtl.Value = Unchecked
        ElseIf TypeName(objCtl) = "DataGrid" Then
            objCtl.Refresh
        ElseIf TypeName(objCtl) = "Image" Then
            If objCtl.Name <> "imgLogo" Then
                objCtl.Picture = Nothing
            End If
        End If
    Next
End Sub

Public Sub ClrRequired(ClrCode As Long)
    For Each objCtl In FrmName
        If TypeName(objCtl) = "ITGTextBox" Then
            If objCtl.Required = True Then
                objCtl.LabelForeColor = ClrCode
            End If
        End If
    Next
End Sub


Public Function ToolbarIndex(KeyCode As Integer, Shift As Integer) As Integer
    If Shift = 2 Then
        Select Case KeyCode
            Case 78 'New (Ctrl+N)
                ToolbarIndex = 1
            Case 69 'Edit (Ctrl+E)
                ToolbarIndex = 2
            Case 68 'Delete (Ctrl+D)
                ToolbarIndex = 3
            Case 45 'New Line (Ctrl+Ins)
                ToolbarIndex = 5
            Case 46 'Delete Line (Ctrl+Del)
                ToolbarIndex = 6
            Case 83 'Save (Ctrl+S)
                ToolbarIndex = 11
            Case 90 'Undo Current (Ctrl+Z)
                ToolbarIndex = 12
            Case 70 'Find (Crtl+F)
                ToolbarIndex = 14
            Case 80 'Print (Ctrl+P)
                ToolbarIndex = 21
            Case 88 'Close Window (Ctrl+X)
                ToolbarIndex = 22
            Case 38 'First Record
                ToolbarIndex = 16
            Case 37 'Previous Record
                ToolbarIndex = 17
            Case 39 'Next Record
                ToolbarIndex = 18
            Case 40 'Last Record
                ToolbarIndex = 19
            Case Else
                ToolbarIndex = 0
        End Select
    Else
        ToolbarIndex = 0
    End If
End Function

Public Sub ToolbarFunction(Index As Integer)
    With FrmName
        Select Case Index
            Case 1
                .TBNew
            Case 2
                .TBEdit
            Case 3
                .TBDelete
            Case 5
                .TBNewLine
            Case 6
                .TBDeleteLine
            Case 8
                .TBPostRecord
            Case 9
                .TBCancelRecord
            Case 11
                .TBSave
            Case 12
                .TBUndoAll
            
            Case 14
                .TBFindPrimary
            Case 16
                .TBFirstRec
            Case 17
                .TBPrevRec
            Case 18
                .TBNextRec
            Case 19
                .TBLastRec
            
            Case 21
                .TBPrintRecord
            Case 22
                .TBCloseWindow
            Case 24
                .TBAccountAffected
            Case 25
                .TBReference
            Case 26
                .TBNotify
        End Select
    End With
End Sub

Public Sub LinkForm(frm As Object, ModName As String, RefCode As String)
    With frm
        If .Mode = 1 Then
            MsgBox "Sytem detected that '" & Trim(ModName) & "' is in Add/Edit mode." & _
                    vbCr & "Please save/undo the current transaction.", vbCritical + vbOKOnly, "Comunion"
            FrmName.SetFocus
            Exit Sub
        Else
            .Show
            .ZOrder
            .ShowForm (RefCode)
        End If
    End With
End Sub

'This sub binds the controls to the recordset
Public Sub BindControls(rs As ADODB.Recordset)
    
    For Each objCtl In FrmName
        If TypeName(objCtl) = "ITGTextBox" Then
            Set objCtl.DataSource = rs
        ElseIf TypeName(objCtl) = "ITGDateBox" Then
            Set objCtl.DataSource = rs
        ElseIf TypeName(objCtl) = "ComboBox" Then
            Set objCtl.DataSource = rs
        ElseIf TypeName(objCtl) = "ITGCheckBox" Then
            Set objCtl.DataSource = rs
        ElseIf TypeName(objCtl) = "PictureBox" Then
            Set objCtl.DataSource = rs
        ElseIf TypeName(objCtl) = "Image" Then
            Set objCtl.DataSource = rs
        ElseIf TypeName(objCtl) = "RichTextBox" Then
            Set objCtl.DataSource = rs
        End If
    Next

End Sub

'This sub unbinds the controls to the recordset
Public Sub UnbindControls()
    
    For Each objCtl In FrmName
        If TypeName(objCtl) = "ITGTextBox" Then
            Set objCtl.DataSource = Nothing
        ElseIf TypeName(objCtl) = "ITGDateBox" Then
            Set objCtl.DataSource = Nothing
        ElseIf TypeName(objCtl) = "ComboBox" Then
            Set objCtl.DataSource = Nothing
        ElseIf TypeName(objCtl) = "ITGCheckBox" Then
            Set objCtl.DataSource = Nothing
        ElseIf TypeName(objCtl) = "PictureBox" Then
            Set objCtl.DataSource = Nothing
        ElseIf TypeName(objCtl) = "Image" Then
            Set objCtl.DataSource = Nothing
        ElseIf TypeName(objCtl) = "RichTextBox" Then
            Set objCtl.DataSource = Nothing
        End If
    Next

End Sub

Public Sub FormSetup()
    With FrmName
        .BackColor = &HF7D9C2
        .Top = FormPosTop
        .Left = FormPosLeft
        If .Width < FormWidth Then .Width = FormWidth
        If .Height < FormHeight Then .Height = FormHeight
    End With
End Sub
Public Sub CloseMenuTab(frm As Object)
    frm.MenuTab1.RemoveTab
End Sub

Public Sub CancelTabChange(frm As Object)
    frm.MenuTab1.CancelTabChange
End Sub

Public Sub AllowTabChange(frm As Object)
    frm.MenuTab1.AllowTabChange
End Sub

Public Sub PreviousTab(frm As Object)
    frm.MenuTab1.PreviousTab
End Sub

Public Property Get FrmName() As Object
    Set FrmName = mFrmName
End Property

Public Property Set FrmName(ByVal sFrmName As Object)
   Set mFrmName = sFrmName
End Property

Public Property Get FormWidth() As Long
    FormWidth = mFormWidth
End Property

Public Property Let FormWidth(ByVal sFormWidth As Long)
    mFormWidth = sFormWidth
End Property

Public Property Get FormHeight() As Long
    FormHeight = mFormHeight
End Property

Public Property Let FormHeight(ByVal sFormHeight As Long)
    mFormHeight = sFormHeight
End Property

Public Property Get FormPosLeft() As Long
    FormPosLeft = mFormPosLeft
End Property

Public Property Let FormPosLeft(ByVal sFormPosLeft As Long)
    mFormPosLeft = sFormPosLeft
End Property

Public Property Get FormPosTop() As Long
    FormPosTop = mFormPosTop
End Property

Public Property Let FormPosTop(ByVal sFormPosTop As Long)
    mFormPosTop = sFormPosTop
End Property
